import RAP from './rap2.js'
import Mock from 'mockjs'
Mock.setup({
  timeout: 1000
})
export function MockXHR () {
  for (const repositoryId in RAP.interfaces) {
    for (const itf of RAP.interfaces[repositoryId]) {
      // Mock.mock(itf.url, itf.method.toLowerCase(), settings => {
      Mock.mock(RegExp(itf.url + '.*'), itf.method.toLowerCase(), settings => {
        // console.log(`Mock ${itf.method} ${itf.url} =>`, itf.response)
        const res = (typeof itf.response == 'function') ? itf.response(itf.request) : itf.response
        return {
          code: 200,
          data: Mock.mock(res)
        }
      })
    }
  }
}
